<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>计算三角形的第三个角的度数</title>
</head>
<body>
  <form name="angle" action="result.jsp" method="post">
    <fieldset>
      <!-- 表单文本框的值不可为空且只接受输入正整数，两者之和必须大于0且小于180 -->
      <legend>输入三角形的前两个角的度数</legend>
      <input type="text" name="first" placeholder="第一个角的度数" onkeypress="return verify(window.event)">
      <input type="text" name="second" placeholder="第二个角的度数" onkeypress="return verify(event)">
      <input type="submit" name="计算" onclick="return verifyResult()">
    </fieldset>
  </form>
</body>
<script>
    function verify(obj) {
      var length = obj.target.value.length;
      if (length > 2) {
        return false;
      }
      var c = String.fromCharCode(obj.charCode);
      var exp = /^\d$/;
      return exp.test(c);
    }
    function verifyResult() {
      var v1 = document.angle.first.value;
      var v2 = document.angle.second.value;
      if (v1 == null || v1 == '' || v2 == null || v2 == '') {
        return false;
      }
      var a1 = parseInt(v1);
      var a2 = parseInt(v2);
      return (0 < a1 + a2 < 180);
    }
</script>
</html>